package com.geek.controller;

import com.geek.entity.Course;
import com.geek.service.CourseService;
import com.geek.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.List;

/**
 * @ClassName CourseController
 * @Description TODO
 * @Author Lambert
 * @Date 2021/6/10 20:45
 * @Version 1.0
 **/
@Controller
public class IndexController {
    @Autowired
    CourseService courseService;
    /**
     * 跳转课程首页
     * @return
     */
    @GetMapping("index")
    public String index() {
        return "index";
    }

    /**
     * 跳转课程明细
     * @param id
     * @param modelMap
     * @return
     */
    @GetMapping("coursedetail/{id}")
    public String coursedetail(@PathVariable("id")String id, ModelMap modelMap){
        modelMap.put("course",courseService.getById(id));
        return "coursedetail";
    }


    /**
     * 查询产品课程接口
     * @return
     */
    @ResponseBody
    @GetMapping("/loadcourse")
    public R loadCourse() {
        //1:执行课程查询
        List<Course> courses = courseService.list();
        //2:统一返回处理
        return R.ok().data("courses",courses);
    }



}